import { _ as _export_sfc, x as useMainStore, y as storeToRefs, z as ref, al as useNavbarHeight, c as createBlock, w as withCtx, n as normalizeStyle, H as unref, i as index$g, j as resolveEasycom, k as resolveDynamicComponent, o as openBlock, b as createVNode, Q as index$x, t as createTextVNode, u as toDisplayString, ag as navigateBack } from './index-Cc4oxzDN.js';
import { b as __easycom_5 } from './uv-toast.nS_Liirv.js';
import { b as userLogout } from './auth.CJjHezpF.js';
import './uv-loading-icon.DuNkB54M.js';
import './platform.EIa5ETLd.js';

const _sfc_main = {
  __name: 'logout',
  setup(__props) {

const main = useMainStore();
const { member, isLogin } = storeToRefs(main);
const uToast = ref();
ref('退出');
const isLoading = ref(false);

// 获取导航栏高度
const { navbarHeightCss } = useNavbarHeight();

const logout = async () => {
	if (isLoading.value) return;
	
	try {
		isLoading.value = true;
		console.log('用户点击退出登录');
		
		// 显示退出提示
		uToast.value.show({
			message: '正在退出...',
			type: 'loading'
		});
		
		// 调用后端退出接口
		try {
		    const result = await userLogout();
		    console.log('后端退出接口调用成功:', result);
		} catch (error) {
		    console.log('后端退出接口调用失败，但继续执行本地退出:', error);
		}
		
		// 调用store中的logout方法
		main.logout();
		
		// 显示成功提示
		uToast.value.show({
			message: '已退出登录',
			type: 'success'
		});
		
		// 延迟返回，让用户看到成功提示
		setTimeout(() => {
			console.log('退出登录完成，返回上一页');
			navigateBack();
		}, 1500);
		
	} catch (error) {
		console.error('退出登录过程中出现错误:', error);
		
		// 即使出错也要清除本地数据
		main.logout();
		
		uToast.value.show({
			message: '退出登录完成',
			type: 'success'
		});
		
		setTimeout(() => {
			navigateBack();
		}, 1500);
		
	} finally {
		isLoading.value = false;
	}
};
	

return (_ctx, _cache) => {
  const _component_v_uni_button = index$x;
  const _component_uv_toast = resolveEasycom(resolveDynamicComponent("uv-toast"), __easycom_5);
  const _component_v_uni_view = index$g;

  return (openBlock(), createBlock(_component_v_uni_view, {
    class: "top",
    style: normalizeStyle(`padding-top: ${unref(navbarHeightCss)};`)
  }, {
    default: withCtx(() => [
      createVNode(_component_v_uni_button, {
        type: "primary",
        size: "default",
        class: "login-btn",
        onClick: logout,
        loading: isLoading.value
      }, {
        default: withCtx(() => [
          createTextVNode(toDisplayString(isLoading.value ? '退出中...' : '确定退出登录'), 1)
        ]),
        _: 1
      }, 8, ["loading"]),
      createVNode(_component_uv_toast, {
        ref_key: "uToast",
        ref: uToast
      }, null, 512)
    ]),
    _: 1
  }, 8, ["style"]))
}
}

};
const logout = /*#__PURE__*/_export_sfc(_sfc_main, [['__scopeId',"data-v-30b430e2"]]);

export { logout as default };
